#!/usr/bin/python

"""
A structure that finds the sum of two inputs.
"""

import sys

from utils import *
from structure import Structure
from logger import logger

class AdderError(Exception):
    """
    handling class for adder exceptions
    """
    
    def __init__(self, msg):
        """
        initialize the class
        """
        logger.error("adder: %s" % msg)

class Adder(Structure):
    """
    This adder takes two arguments. The result is stored in a local variable.
    """
    
    def __init__(self, dim = ADDER_DIMENSION):
        """
        initialize the adder
        """
        #TODO adders should always be a single row of cells?
        Structure.__init__(self, dim, 2, '+')
        
    def compute(self):
        """
        use the inputs to calculate an output
        """
        #throw exception if not two inputs
        if len(self.inputs) != 2:
            raise AdderError('exactly 2 inputs required')
        
        (carry_out, self.result) = bitstring_add(self.inputs[0], self.inputs[1], '0')
